﻿@using EasyCourse.Model;
@{
    Layout = null;
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
    var courseOtherInfoTypeDic = CourseOtherInfoManage.Instance.CourseOtherInfoTypeDic;
    ViewData["TypeCode"] = Model.TypeCode;
}
@model CourseOtherInfo
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>精品课程管理</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav4Teacher.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">
                @pageInfo.CourseName<br>
            <small>广州中医药大学康复治疗微课程网络学习平台</small>
        </h1>
    </div>
</div>
@Html.Partial("~/Views/Share/PublicTeacherNaviMenu.cshtml", 0)
<div class="container">
    <div class="row">
        @Html.Partial("~/Views/Share/PublicCourseOtherInfoMenu.cshtml", this.ViewData)
        <div class="col-xs-10">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <ol class="breadcrumb">
                            <li>精品课程管理</li>
                            <li>@courseOtherInfoTypeDic[Model.TypeCode.Value]</li>
                            <li class="active">内容管理</li>
                        </ol>
                    </h3>
                </div>
                <div class="panel-body">
                    <ul id="myTab" class="nav nav-tabs">
                        <li class="@(Model.IsSimpleType.Value ? "active" : "")"><a href="#home" data-toggle="tab">简单类型</a></li>
                        <li class="@(Model.IsSimpleType.Value ? "" : "active")"><a href="#ios" data-toggle="tab">复杂类型</a></li>
                    </ul>
                    <div id="myTabContent" class="tab-content mt15">
                        <div class="tab-pane fade @(Model.IsSimpleType.Value ? "in active" : "") " id="home">
                            <div class="row">
                                <form id="valid_form1" action="@Url.Action("CourseOtherInfoContentEdit", "CourseOtherInfo")" method="post" class="form-horizontal" role="form">
                                    @Html.HiddenFor(model => model.Id)
                                    @Html.Hidden("PId")
                                    @Html.Hidden("CourseId")
                                    @Html.Hidden("TypeCode")
                                    @Html.Hidden("IsMenu", false)
                                    @Html.Hidden("IsSimpleType", true)
                                    <div class="form-group">
                                        <label class="col-xs-2 control-label" for="Title">名称:</label>
                                        <div class="col-xs-6">
                                            <input type="text" name="Title" value="@Model.Title" class="form-control input-md" id="Title">
                                        </div>
                                        <div class="col-xs-4"></div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-xs-2" for="StatusCode">是否发布:</label>
                                        <div class="col-xs-2">
                                            <select class="form-control input-sm" name="StatusCode">
                                                @if (Model.IsSimpleType.Value)
                                                {
                                                    <option value="4" @(Model.StatusCode == 4 ? "selected" : "")>是</option>
                                                    <option value="0" @(Model.StatusCode == 4 ? "" : "selected")>否</option>
                                                }
                                                else
                                                {
                                                    <option value="4" selected>是</option>
                                                    <option value="0">否</option>
                                                }

                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-xs-2">已选文件:</label>
                                        <div class="col-xs-6">
                                            <input type="hidden" name="CourseContent" value="@(Model.IsSimpleType.Value ? Model.CourseContent : "")" />
                                            <input name="fileName" id="JfileName" value="@(Model.IsSimpleType.Value ? Model.CourseContent.Substring(Model.CourseContent.LastIndexOf('/')+1) : "未选择文件")" class="form-control mb10" readonly="readonly" />
                                            <input id="file_upload" name="file_upload" type="file" class="form-control input-sm">

                                        </div>
                                        <div class="col-xs-4"></div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-xs-offset-2 col-xs-10">
                                            <button type="button" onclick="autoSubmit('valid_form1')" class="btn btn-success btn-md"><span class="glyphicon glyphicon-ok"></span>保存</button>
                                            <button type="button" onclick="history.go(-1)" class="btn btn-success btn-md"><span class="glyphicon glyphicon-arrow-left"></span>返回</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <div class="tab-pane fade @(Model.IsSimpleType.Value ? "" : "in active")" id="ios">
                            <div class="row">
                                <form id="valid_form2" action="@Url.Action("CourseOtherInfoContentEdit", "CourseOtherInfo")" method="post" class="form-horizontal" role="form">
                                    @Html.HiddenFor(model => model.Id)
                                    @Html.Hidden("PId")
                                    @Html.Hidden("CourseId")
                                    @Html.Hidden("TypeCode")
                                    @Html.Hidden("IsMenu", false)
                                    @Html.Hidden("IsSimpleType", false)
                                    <div class="form-group">
                                        <label class="col-xs-2 control-label" for="Title">名称:</label>
                                        <div class="col-xs-6">
                                            <input type="text" name="Title" value="@Model.Title" class="form-control input-md">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-xs-2">是否发布:</label>
                                        <div class="col-xs-2">
                                            <select class="form-control input-sm" name="StatusCode">
                                                @if (Model.IsSimpleType.Value)
                                                {
                                                    <option value="4" @(Model.StatusCode == 4 ? "selected" : "")>是</option>
                                                    <option value="0" @(Model.StatusCode == 4 ? "" : "selected")>否</option>
                                                }
                                                else
                                                {
                                                    <option value="4" selected>是</option>
                                                    <option value="0">否</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-xs-offset-2 col-xs-10">
                                            <textarea id="CourseContent" name="CourseContent" class="form-control" style="width: 100%; height: 300px;">
                                                @(Model.IsSimpleType.Value ? "" : Model.CourseContent)
                                            </textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-xs-offset-2 col-xs-10">
                                            <button type="button" onclick="autoSubmit('valid_form2')" class="btn btn-success btn-md"><span class="glyphicon glyphicon-ok"></span>保存 </button>
                                            <button type="button" onclick="history.go(-1)" class="btn btn-success btn-md"><span class="glyphicon glyphicon-arrow-left"></span>返回</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@Html.Partial("~/Views/Share/PublicFooter.cshtml")
@Html.Partial("~/Views/Share/PublicCommonJs.cshtml")

<script src="~/Content/jquery.form.js"></script>
@*kindeditor.js有自己修改过 For Ckplayer*@
<script src="../Content/kindeditor/kindeditor.js"></script>
<script src="../Content/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src=@Url.Content("~/Content/uploadify/jquery.uploadify.min.js?ver=")@DateTime.Now.Ticks></script>
<link href="../Css/uploadify.css" rel="stylesheet" />
<script src="../Content/kindeditor/plugins/insertVideo/ckplayer/ckplayer.js"></script>
<script>

    $(function () {

        $("#file_upload").uploadify({
            'queueSizeLimit': 1,
            'formData': { 'fileType': 'CourseInfo' },
            'buttonText': '请选择上传文件',
            'swf': '@Url.Content("~/Content/uploadify/uploadify.swf")',
            'uploader': '@Url.Action("Upload", "Base")',
            'onUploadSuccess': function (file, data, response) {
                var json = $.parseJSON(data);
                if (json.result) {
                    $("#JfileName").val(file.name);
                    $("#JfileName").attr("data-fileUrl", json.message);
                    $("input[type=hidden][name='CourseContent']").val(json.message);
                }
                else {
                    showTips.open(json.message);
                }
            }
        });
    });


    KindEditor.ready(function (K) {
        window.editor = K.create('#CourseContent', {
            uploadJson: '@Url.Content("~/upload_json.ashx")',
            fileManagerJson: '@Url.Content("~/file_manager_json.ashx")',
            allowFileManager: true
        });
    });


    var t = true;
    function autoSubmit(frmId) {
        var jsonData;

        if (frmId == "valid_form1") {
            var frm1 = $("#valid_form1");
            var Id = frm1.find("#Id").val();
            var PId = frm1.find("#PId").val();
            var CourseId = frm1.find("#CourseId").val();
            var TypeCode = frm1.find("#TypeCode").val();
            var IsMenu = frm1.find("#IsMenu").val();
            var IsSimpleType = frm1.find("#IsSimpleType").val();
            var Title = frm1.find("#Title").val();
            var StatusCode = frm1.find("select[name='StatusCode'] option:selected").val();
            var CourseContent = frm1.find("input[name='CourseContent']").val();
            jsonData = {
                "Id": Id,
                "PId": PId,
                "CourseId": CourseId,
                "TypeCode": TypeCode,
                "IsMenu": IsMenu,
                "IsSimpleType": IsSimpleType,
                "Title": Title,
                "StatusCode": StatusCode,
                "CourseContent": CourseContent
            };
        }
        else {
            var frm2 = $("#valid_form2");
            var Id = frm2.find("#Id").val();
            var PId = frm2.find("#PId").val();
            var CourseId = frm2.find("#CourseId").val();
            var TypeCode = frm2.find("#TypeCode").val();
            var IsMenu = frm2.find("#IsMenu").val();
            var IsSimpleType = frm2.find("#IsSimpleType").val();
            var Title = frm2.find("input[name='Title']").val();
            var StatusCode = frm2.find("select[name='StatusCode'] option:selected").val();
            var CourseContent = editor.html();
            jsonData = {
                "Id": Id,
                "PId": PId,
                "CourseId": CourseId,
                "TypeCode": TypeCode,
                "IsMenu": IsMenu,
                "IsSimpleType": IsSimpleType,
                "Title": Title,
                "StatusCode": StatusCode,
                "CourseContent": CourseContent
            };
        }

        editor.sync();
        $.easyPost("@Url.Action("CourseOtherInfoContentEdit", "CourseOtherInfo")", jsonData, function (data) {
            if (data.result) {
                showTips.open("编辑成功！");
            } else {
                showTips.open(data.message)
            }
        }, "json")






        @*            $("#CourseContent").val("");
            var postData = $("#" + frmId).formSerialize();
            postData = postData.replace("CourseContent=", "CourseContent=" + editor.html());
            var url = "@Url.Action("CourseOtherInfoContentEdit", "CourseOtherInfo")";
            var options = {
                type: 'POST',
                data: postData,
                url: url,
                async: false,
                cache: false,
                success: function (data) {
                    if (data.result) {
                        showTips.open("编辑成功");
                    }
                    else {
                        showTips.open(data.message);
                    }
                }

            }
            if (t) {
                t = false;
                $.ajax(options);
                t = true;
            }*@
    };



</script>
</body>
</html>

